home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / MovingObject.as < prev    next >
Text File  |  2013-04-24  |  6KB  |  227 lines

  1. class MovingObject extends State
  2. {
  3.    static var sSTATE_IDLE_UP = "IdleUp";
  4.    static var sSTATE_IDLE_DOWN = "IdleDown";
  5.    static var sSTATE_IDLE_LEFT = "IdleLeft";
  6.    static var sSTATE_IDLE_RIGHT = "IdleRight";
  7.    static var sSTATE_LEFT = "Left";
  8.    static var sSTATE_RIGHT = "Right";
  9.    static var sSTATE_UP = "Up";
  10.    static var sSTATE_DOWN = "Down";
  11.    static var nMAX_MOVEMENT = 20;
  12.    function MovingObject(_mcRef)
  13.    {
  14.       super(_mcRef);
  15.       this.setState(MovingObject.sSTATE_RIGHT);
  16.       this.nCurrentDir = CTRLGame.nDIR_RIGHT;
  17.       this.nMovement = 0;
  18.    }
  19.    function get FuturePos()
  20.    {
  21.       var _loc2_ = new Object();
  22.       _loc2_.x = 0;
  23.       _loc2_.y = 0;
  24.       switch(this.sState)
  25.       {
  26.          case MovingObject.sSTATE_UP:
  27.             _loc2_.x = this.mcRef._x;
  28.             _loc2_.y = this.mcRef._y - this.nMovement;
  29.             break;
  30.          case MovingObject.sSTATE_DOWN:
  31.             _loc2_.x = this.mcRef._x;
  32.             _loc2_.y = this.mcRef._y + this.nMovement;
  33.             break;
  34.          case MovingObject.sSTATE_LEFT:
  35.             _loc2_.x = this.mcRef._x - this.nMovement;
  36.             _loc2_.y = this.mcRef._y;
  37.             break;
  38.          case MovingObject.sSTATE_RIGHT:
  39.             _loc2_.x = this.mcRef._x + this.nMovement;
  40.             _loc2_.y = this.mcRef._y;
  41.             break;
  42.          default:
  43.             _loc2_.x = this.mcRef._x;
  44.             _loc2_.y = this.mcRef._y;
  45.       }
  46.       return _loc2_;
  47.    }
  48.    function getMiCasePos()
  49.    {
  50.       var _loc2_ = 0.5 * MovingObject.nMAX_MOVEMENT;
  51.       var _loc3_ = new Object();
  52.       _loc3_.x = 0;
  53.       _loc3_.y = 0;
  54.       switch(this.sState)
  55.       {
  56.          case MovingObject.sSTATE_UP:
  57.             _loc3_.x = this.mcRef._x;
  58.             _loc3_.y = this.mcRef._y - _loc2_;
  59.             break;
  60.          case MovingObject.sSTATE_DOWN:
  61.             _loc3_.x = this.mcRef._x;
  62.             _loc3_.y = this.mcRef._y + _loc2_;
  63.             break;
  64.          case MovingObject.sSTATE_LEFT:
  65.             _loc3_.x = this.mcRef._x - _loc2_;
  66.             _loc3_.y = this.mcRef._y;
  67.             break;
  68.          case MovingObject.sSTATE_RIGHT:
  69.             _loc3_.x = this.mcRef._x + _loc2_;
  70.             _loc3_.y = this.mcRef._y;
  71.             break;
  72.          default:
  73.             _loc3_.x = this.mcRef._x;
  74.             _loc3_.y = this.mcRef._y;
  75.       }
  76.       return _loc3_;
  77.    }
  78.    function get Moving()
  79.    {
  80.       return this.nMovement != 0;
  81.    }
  82.    function getWishPos(_nDir)
  83.    {
  84.       var _loc3_ = new Object();
  85.       _loc3_.x = 0;
  86.       _loc3_.y = 0;
  87.       switch(_nDir)
  88.       {
  89.          case CTRLGame.nDIR_UP:
  90.             _loc3_.x = this.mcRef._x;
  91.             _loc3_.y = this.mcRef._y - MovingObject.nMAX_MOVEMENT;
  92.             break;
  93.          case CTRLGame.nDIR_DOWN:
  94.             _loc3_.x = this.mcRef._x;
  95.             _loc3_.y = this.mcRef._y + MovingObject.nMAX_MOVEMENT;
  96.             break;
  97.          case CTRLGame.nDIR_LEFT:
  98.             _loc3_.x = this.mcRef._x - MovingObject.nMAX_MOVEMENT;
  99.             _loc3_.y = this.mcRef._y;
  100.             break;
  101.          case CTRLGame.nDIR_RIGHT:
  102.             _loc3_.x = this.mcRef._x + MovingObject.nMAX_MOVEMENT;
  103.             _loc3_.y = this.mcRef._y;
  104.             break;
  105.          default:
  106.             _loc3_.x = this.mcRef._x;
  107.             _loc3_.y = this.mcRef._y;
  108.       }
  109.       return _loc3_;
  110.    }
  111.    function getWishMidPos(_nDir)
  112.    {
  113.       var _loc3_ = new Object();
  114.       _loc3_.x = 0;
  115.       _loc3_.y = 0;
  116.       switch(_nDir)
  117.       {
  118.          case CTRLGame.nDIR_UP:
  119.             _loc3_.x = this.mcRef._x;
  120.             _loc3_.y = this.mcRef._y - 0.5 * MovingObject.nMAX_MOVEMENT;
  121.             break;
  122.          case CTRLGame.nDIR_DOWN:
  123.             _loc3_.x = this.mcRef._x;
  124.             _loc3_.y = this.mcRef._y + 0.5 * MovingObject.nMAX_MOVEMENT;
  125.             break;
  126.          case CTRLGame.nDIR_LEFT:
  127.             _loc3_.x = this.mcRef._x - 0.5 * MovingObject.nMAX_MOVEMENT;
  128.             _loc3_.y = this.mcRef._y;
  129.             break;
  130.          case CTRLGame.nDIR_RIGHT:
  131.             _loc3_.x = this.mcRef._x + 0.5 * MovingObject.nMAX_MOVEMENT;
  132.             _loc3_.y = this.mcRef._y;
  133.             break;
  134.          default:
  135.             _loc3_.x = this.mcRef._x;
  136.             _loc3_.y = this.mcRef._y;
  137.       }
  138.       return _loc3_;
  139.    }
  140.    function canMove()
  141.    {
  142.       var _loc2_ = false;
  143.       if(!Controller.getRef().isPaused() && !CTRLGame.getRef().Screen.isInMiniGame())
  144.       {
  145.          _loc2_ = true;
  146.       }
  147.       return _loc2_;
  148.    }
  149.    function inverseDirection(_nCurrentDir)
  150.    {
  151.       switch(_nCurrentDir)
  152.       {
  153.          case CTRLGame.nDIR_UP:
  154.             var _loc3_ = CTRLGame.nDIR_DOWN;
  155.             break;
  156.          case CTRLGame.nDIR_DOWN:
  157.             _loc3_ = CTRLGame.nDIR_UP;
  158.             break;
  159.          case CTRLGame.nDIR_LEFT:
  160.             _loc3_ = CTRLGame.nDIR_RIGHT;
  161.             break;
  162.          case CTRLGame.nDIR_RIGHT:
  163.             _loc3_ = CTRLGame.nDIR_LEFT;
  164.       }
  165.       return _loc3_;
  166.    }
  167.    function isTrackOkay(_nFutureDir)
  168.    {
  169.       var _loc3_ = false;
  170.       var _loc4_ = this.getWishPos(_nFutureDir);
  171.       var _loc5_ = CTRLGame.getRef().Maze.getVTracks(_loc4_.x,_loc4_.y);
  172.       var _loc6_ = CTRLGame.getRef().Maze.getHTracks(_loc4_.x,_loc4_.y);
  173.       switch(_nFutureDir)
  174.       {
  175.          case CTRLGame.nDIR_UP:
  176.          case CTRLGame.nDIR_DOWN:
  177.             for(var i in _loc5_)
  178.             {
  179.                if(_loc5_[i].hitTest(_loc4_.x,_loc4_.y,true))
  180.                {
  181.                   _loc3_ = true;
  182.                   break;
  183.                }
  184.             }
  185.             break;
  186.          case CTRLGame.nDIR_LEFT:
  187.          case CTRLGame.nDIR_RIGHT:
  188.             for(var i in _loc6_)
  189.             {
  190.                if(_loc6_[i].hitTest(_loc4_.x,_loc4_.y,true))
  191.                {
  192.                   _loc3_ = true;
  193.                   break;
  194.                }
  195.             }
  196.       }
  197.       return _loc3_;
  198.    }
  199.    function manageMovement()
  200.    {
  201.    }
  202.    function IdleUp()
  203.    {
  204.    }
  205.    function IdleDown()
  206.    {
  207.    }
  208.    function IdleLeft()
  209.    {
  210.    }
  211.    function IdleRight()
  212.    {
  213.    }
  214.    function Left()
  215.    {
  216.    }
  217.    function Up()
  218.    {
  219.    }
  220.    function Right()
  221.    {
  222.    }
  223.    function Down()
  224.    {
  225.    }
  226. }
  227.